﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ServiceApplication.Service.Basic;
using CommonLibrary.DataModel.Basic;
using OAclient.Filters;

namespace OAclient.Controllers
{

    [ExceptionFilter]
    [LoggerFilter]
    public class RegisterController : Controller
    {
        BasicService bs = new BasicService();
        //
        // GET: /Register/

        public ActionResult RegisterPartial()
        {
            var dept = bs.QueryAllDepts();
            var duty = bs.QueryAllDutys();
            List<SelectListItem> list_dept = new List<SelectListItem>();
            for (int i = 0; i < dept.Rows.Count; i++)
            {
                list_dept.Add(new SelectListItem
                {
                    Selected = false,
                    Text = dept.Rows[i]["部门名称"].ToString(),
                    Value = dept.Rows[i]["部门编码"].ToString(),
                });
            }
            List<SelectListItem> list_duty = new List<SelectListItem>();
            for (int i = 0; i < duty.Rows.Count; i++)
            {
                list_duty.Add(new SelectListItem
                {
                    Selected = false,
                    Text = duty.Rows[i]["职位名称"].ToString(),
                    Value = duty.Rows[i]["职位编码"].ToString(),
                });
            }
            ViewData["list_dept"] = list_dept;
            ViewData["list_duty"] = list_duty;
            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public string DoAddUser(string login_id, string user_name, string login_password, string dept_id, string duty_id)
        {
            UserEntity user = new UserEntity()
            {
                user_name = user_name,
                user_loginid = login_id,
                user_psw = login_password,
                //user_cime = DateTime.Now.ToString(),
                // dept_id = int.Parse(dept_id),
                //duty_id = int.Parse(duty_id),
            };
            bs.AddUser(user);
            return "添加成功！";
        }


    }
}
